<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>内置对象Date</title>
		<script type="text/javascript">

			function demo(){
				//创建一个date对象
				let dat = new Date(); //获取当前时间
				
				//获取年月日并输出
				let year = dat.getFullYear();
				let month = dat.getMonth() + 1; //dat.getMonth();月份返回值为0~11
				let date = dat.getDate();
				
				let lap = year + "年" + month + "月" + date + "日";
				console.log(lap);
				
				//获取时分秒
				let hours = dat.getHours();
				let minutes = dat.getMinutes() < 10 ? "0" + dat.getMinutes() : dat.getMinutes();
				let seconds = dat.getSeconds();
				let min = hours + ":" + minutes + "分" + seconds + "秒";
				console.log(min);
				
				//星期几
				let arr = ["星期天","星期一","星期二","星期三","星期四","星期五","星期六",];
				let xingqi = dat.getDay(); //dat.getDay();返回0~6的数字
				console.log(arr[xingqi]);
				
				console.log(lap + " " + min + " " + arr[xingqi]);
				setTimeout(demo, 1000); // 每1秒执行一次
			}
			
			  demo()
		</script>
	</head>
	<body>
	</body>
</html>